package kr.hkit.password.adapter;

import java.util.List;

import kr.hkit.password.R;
import kr.hkit.password.dto.ChangeItem;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CustomChangeAdapter extends ArrayAdapter<ChangeItem> {

	Context context;
	List<ChangeItem> changeItemList;
	int layoutResID;

	public CustomChangeAdapter(Context context, int layoutResID,
			List<ChangeItem> changeItemList) {
		super(context, layoutResID, changeItemList);
		this.context = context;
		this.changeItemList = changeItemList;
		this.layoutResID = layoutResID;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ChangeItemHolder changeHolder;
		View view = convertView;

		LayoutInflater inflater = ((Activity) context).getLayoutInflater();
		changeHolder = new ChangeItemHolder();

		view = inflater.inflate(layoutResID, parent, false);
		changeHolder.ItemName = (TextView) view
				.findViewById(R.id.change_itemName);
		changeHolder.tDate = (TextView) view.findViewById(R.id.change_date);

		view.setTag(changeHolder);

		ChangeItem cItem = (ChangeItem) this.changeItemList.get(position);

		changeHolder.ItemName.setText(cItem.getItemName());
		changeHolder.tDate.setText(cItem.getDate());

		return view;
	}

	private static class ChangeItemHolder {
		TextView ItemName;
		TextView tDate;
	}
}